import { LoginParams, Result, Token } from '@/types/http'
import request from '@/utils/request'
import axios from 'axios'

/**
 * 登录
 * @param data 登录表单
 */
export const loginApi = (data: LoginParams) => {
  return request<Token>({
    method: 'post',
    url: '/authorizations',
    data
  })
}

/**
 * 获取验证码
 * @param mobile 手机号
 */
export const sendCodeApi = (mobile: string) => {
  return request<null>({
    method: 'get',
    url: `sms/codes/${mobile}`
  })
}

/**
 * 获取新token
 * @param refresh_token 
 */
export const refreshTokenApi = (refresh_token: string) => {
  return axios.request<Result<{ token: string }>>({
    method: 'put',
    url: 'https://toutiao.itheima.net/v1_0/authorizations',
    headers: {
      Authorization: `Bearer ${refresh_token}`
    }
  })
}